"""
    迭代器
"""
from collections.abc import  Iterator, Iterable

import os

list = [1,2,3]
for element in list:
    print(element)

# 自定义迭代器
class MyIterator:
    """
        自定义的迭代器,遍历是从后往前遍历
    """
    def __init__(self,data):
        # data 表示数据
        self.data = data
        # index 表示索引位置
        self.index = len(data)

    # 迭代器必须实现的方法
    def __iter__(self):
        return self

    def __next__(self):
        if(self.index == 0):
            raise StopIteration
        else:
            self.index = self.index - 1
            return self.data[self.index]


list = MyIterator([10,30,20,80])

# print(next(list))
# print(next(list))
# print(next(list))
# print(next(list))
# print(next(list))

for item in list:
    print(item)